package practice_0526;

public class practice05_ticket {
    public static void main(String[] args) {
        ticket ticket1 = new ticket();
        ticket ticket2 = new ticket();
        ticket ticket3 = new ticket();
        ticket1.start();
        ticket2.start();
        ticket3.start();
    }
}
class ticket extends Thread {
    private static int ticket_count = 100;

    @Override
    public void run() {
        while (ticket_count > 0) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "卖出了票，剩余票数" + (--ticket_count) + "张");

        }
//        while(true){
//            if(ticket_count <= 0){
//                System.out.println("售罄");
//                break;
//            }
//            try {
//                Thread.sleep(50);
//
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            System.out.println(Thread.currentThread().getName() + "卖出了票，剩余票数" + (--ticket_count) + "张");
//
//        }

    }
}